package com.bwie.bwedu.net;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import com.bwie.bwedu.application.App;

public class HttpUtils {

	/*
	 * 判断是否有网络
	 */
	public static boolean isNetworkConnected() {
		if (App.getContext() != null) {
			ConnectivityManager mConnectivityManager = (ConnectivityManager) App.getContext()
					.getSystemService(Context.CONNECTIVITY_SERVICE);
			NetworkInfo mNetworkInfo = mConnectivityManager
					.getActiveNetworkInfo();
			if (mNetworkInfo != null) {
				return mNetworkInfo.isAvailable();
			}
		}
		return false;
	}

	/*
	 * 判断WIFI网络是否可用
	 */
//	public static boolean isWifiConnected() {
//		if (App.getContext() != null) {
//			ConnectivityManager mConnectivityManager = (ConnectivityManager) App.getContext()
//					.getSystemService(Context.CONNECTIVITY_SERVICE);
//			NetworkInfo mWiFiNetworkInfo = mConnectivityManager
//					.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
//			if (mWiFiNetworkInfo != null) {
//				return mWiFiNetworkInfo.isAvailable();
//			}
//		}
//		return false;
//	}
	public static boolean isWifiConnected(Context inContext) {
		Context context = inContext.getApplicationContext();
		ConnectivityManager connectivity = (ConnectivityManager) context
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		if (connectivity != null) {
			NetworkInfo[] info = connectivity.getAllNetworkInfo();
			if (info != null) {
				for (int i = 0; i < info.length; i++) {
					if (info[i].getTypeName().equals("WIFI") && info[i].isConnected()) {
						return true;
					}
				}
			}
		}
		return false;
	}

	/*
	 * 判断MOBILE网络是否可用
	 */
	public static boolean isMobileConnected() {
		if (App.getContext() != null) {
			ConnectivityManager mConnectivityManager = (ConnectivityManager) App.getContext()
					.getSystemService(Context.CONNECTIVITY_SERVICE);
			NetworkInfo mMobileNetworkInfo = mConnectivityManager
					.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
			if (mMobileNetworkInfo != null) {
				return mMobileNetworkInfo.isAvailable();
			}
		}
		return false;
	}
}
